#include <iostream>
using namespace std;

struct node
{
	node(int date)
		:_date(date)
		,_next(nullptr)
	{}
	int _date;
	struct node* _next;
};

void test1(node** head)
{
	auto a = new node(1);
	auto b = new node(2);
	auto c = new node(3);
	auto d = new node(4);
	auto e = new node(5);
	auto f = new node(6);
	auto g = new node(7);
	auto h = new node(8);
	*head = a;
	a->_next = b;
	b->_next = c;
	c->_next = d;
	d->_next = e;
	e->_next = f;
	f->_next = g;
	g->_next = h;
}

void test2(node** h)
{
	node* t = *h;
	node* p = (*h)->_next;
	while (p)
	{
		node* cur = p;
		node* parent = nullptr;
		while (cur->_next)
		{
			parent = cur;
			cur = cur->_next;
		}
		if(parent) parent->_next = nullptr;
		if(t) t->_next = cur;
		if(cur)cur->_next = p;
		t = p;
		if(p) p = p->_next;
		if (p && p->_next == nullptr) break;
	}
	
}

void Print(node* cur)
{
	while (cur)
	{
		cout << cur->_date << "->";
		cur = cur->_next;
	}
	cout << "nullptr" << endl;
}
int main()
{
	node * head = nullptr;
	test1(&head);
	test2(&head);
	Print(head);

	return 0;
}